<!DOCTYPE html>

<html>
<head>
  <title>Object</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  <link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
  <div id="container">
    <div id="background"></div>
    
      <ul id="jump_to">
        <li>
          <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
          <a class="small" href="javascript:void(0);">+</a>
          <div id="jump_wrapper">
          <div id="jump_page">
            
              
              <a class="source" href="Array.coffee.html">
                Array.coffee.md
              </a>
            
              
              <a class="source" href="BareObject.coffee.html">
                BareObject.coffee.md
              </a>
            
              
              <a class="source" href="Boolean.coffee.html">
                Boolean.coffee.md
              </a>
            
              
              <a class="source" href="Function.coffee.html">
                Function.coffee.md
              </a>
            
              
              <a class="source" href="Math.coffee.html">
                Math.coffee.md
              </a>
            
              
              <a class="source" href="Maybe.coffee.html">
                Maybe.coffee.md
              </a>
            
              
              <a class="source" href="Nullable.coffee.html">
                Nullable.coffee.md
              </a>
            
              
              <a class="source" href="Number.coffee.html">
                Number.coffee.md
              </a>
            
              
              <a class="source" href="Object.coffee.html">
                Object.coffee.md
              </a>
            
              
              <a class="source" href="Promise.coffee.html">
                Promise.coffee.md
              </a>
            
              
              <a class="source" href="String.coffee.html">
                String.coffee.md
              </a>
            
              
              <a class="source" href="Type.coffee.html">
                Type.coffee.md
              </a>
            
              
              <a class="source" href="header.coffee.html">
                header.coffee.md
              </a>
            
          </div>
        </li>
      </ul>
    
    <ul class="sections">
        
        
        
        <li id="section-1">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-1">&#182;</a>
              </div>
              <h1 id="object">Object</h1>

            </div>
            
            <div class="content"><div class='highlight'><pre>	
	Object.extend = Function.From(Object,Object).To(Object) \
		<span class="hljs-function"><span class="hljs-params">(target,source)</span> -&gt;</span>
			target[key] = source[key] <span class="hljs-keyword">for</span> own key <span class="hljs-keyword">of</span> source
			target
	
	Object.construct = Function.From<span class="hljs-function"><span class="hljs-params">(Function,[Value])</span> <span class="hljs-params">(constructor,args1...)</span> -&gt;</span> <span class="hljs-keyword">switch</span>

		<span class="hljs-keyword">when</span> constructor <span class="hljs-keyword">in</span> [Number,String,Boolean] <span class="hljs-keyword">then</span> constructor
	
		<span class="hljs-keyword">when</span> constructor == Date <span class="hljs-keyword">then</span> <span class="hljs-function"><span class="hljs-params">(args2...)</span> -&gt;</span>
			args = [args1...,args2...]
			<span class="hljs-keyword">switch</span> args.length
				<span class="hljs-keyword">when</span> <span class="hljs-number">1</span> <span class="hljs-keyword">then</span> <span class="hljs-keyword">new</span> Date args[<span class="hljs-number">0</span>]
				<span class="hljs-keyword">when</span> <span class="hljs-number">3</span> <span class="hljs-keyword">then</span> <span class="hljs-keyword">new</span> Date args[<span class="hljs-number">0</span>],args[<span class="hljs-number">1</span>],args[<span class="hljs-number">2</span>]
				<span class="hljs-keyword">when</span> <span class="hljs-number">7</span> <span class="hljs-keyword">then</span> <span class="hljs-keyword">new</span> Date args[<span class="hljs-number">0</span>],args[<span class="hljs-number">1</span>],args[<span class="hljs-number">2</span>],args[<span class="hljs-number">3</span>],args[<span class="hljs-number">4</span>],args[<span class="hljs-number">5</span>],args[<span class="hljs-number">6</span>]
			
		<span class="hljs-keyword">else</span> <span class="hljs-function"><span class="hljs-params">(args2...)</span> -&gt;</span>
			<span class="hljs-keyword">new</span> constructor [args1...,args2...]...
	
	Object.<span class="hljs-function"><span class="hljs-title">valid</span> = <span class="hljs-params">(constructor)</span> -&gt;</span>
		<span class="hljs-keyword">switch</span> constructor
			<span class="hljs-keyword">when</span> Number <span class="hljs-keyword">then</span> <span class="hljs-function"><span class="hljs-params">(number)</span> -&gt;</span> Object.isa(Number)(number) <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> isNan number
			<span class="hljs-keyword">when</span> Date <span class="hljs-keyword">then</span> <span class="hljs-function"><span class="hljs-params">(date)</span> -&gt;</span> Object.isa(Date)(date) <span class="hljs-keyword">and</span> date.toString() != <span class="hljs-string">'Invalid Date'</span>
			<span class="hljs-keyword">else</span> Object.isa(constructor)
	
	Object.<span class="hljs-function"><span class="hljs-title">ensure</span> = <span class="hljs-params">(constructor)</span> -&gt;</span>
		isa = Object.isa constructor
		construct = Object.construct arguments...
		<span class="hljs-function"><span class="hljs-params">(obj)</span> -&gt;</span> <span class="hljs-keyword">if</span> isa obj <span class="hljs-keyword">then</span> obj <span class="hljs-keyword">else</span> construct arguments...
	
	Object.<span class="hljs-function"><span class="hljs-title">copy</span> = <span class="hljs-params">(obj)</span> -&gt;</span> Object.extend {}, obj
	
	Object.<span class="hljs-function"><span class="hljs-title">type</span> = <span class="hljs-params">(obj)</span> -&gt;</span> <span class="hljs-keyword">typeof</span> obj
	
	Object.<span class="hljs-function"><span class="hljs-title">eq</span> = <span class="hljs-params">(value)</span> -&gt;</span> <span class="hljs-function"><span class="hljs-params">(object)</span> -&gt;</span> object == value
	
	Object.keys ?= Function.From(Object).To(Array) \
		<span class="hljs-function"><span class="hljs-params">(object)</span> -&gt;</span> key <span class="hljs-keyword">for</span> own key <span class="hljs-keyword">of</span> object
	
	Object.has = Function.From<span class="hljs-function"><span class="hljs-params">(Scalar)</span> <span class="hljs-params">(key)</span> -&gt;</span>
		Function.From(Object).To(Boolean) \
			<span class="hljs-function"><span class="hljs-params">(object)</span> -&gt;</span> key <span class="hljs-keyword">in</span> Object.keys(object)</pre></div></div>
            
        </li>
        
        
        <li id="section-2">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-2">&#182;</a>
              </div>
              <h2 id="accessors">Accessors</h2>

            </div>
            
            <div class="content"><div class='highlight'><pre>	
	Object.property = Function.overload [
	
		Function.From<span class="hljs-function"><span class="hljs-params">(String,Value)</span> <span class="hljs-params">(property,value)</span> -&gt;</span>
			Function.Requiring( Object.has(property), <span class="hljs-string">'Undefined property'</span> ) \
				<span class="hljs-function"><span class="hljs-params">(obj)</span> -&gt;</span>
					obj[property] = value
					obj
				
		Function.From<span class="hljs-function"><span class="hljs-params">(String)</span> <span class="hljs-params">(property)</span> -&gt;</span>
			<span class="hljs-function"><span class="hljs-params">(obj)</span> -&gt;</span> obj[property]
	
	]
	
	Object.method = Function.overload [	

		Function.From<span class="hljs-function"><span class="hljs-params">(String,[Value])</span> <span class="hljs-params">(method,args1...)</span> -&gt;</span>
			<span class="hljs-function"><span class="hljs-params">(obj,args2...)</span> -&gt;</span>
				<span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Error(<span class="hljs-string">'Undefined method'</span>) <span class="hljs-keyword">unless</span> obj[method]
				obj[method] [args1...,args2...]...

		Function.From<span class="hljs-function"><span class="hljs-params">(Function,[Value])</span> <span class="hljs-params">(fn,args1...)</span> -&gt;</span>
			<span class="hljs-function"><span class="hljs-params">(obj,args2...)</span> -&gt;</span>
				fn.call obj, args1..., args2...

	]
	
	Object.<span class="hljs-function"><span class="hljs-title">resolve</span> = <span class="hljs-params">(name,args1...)</span> -&gt;</span>
		<span class="hljs-function"><span class="hljs-params">(obj,args2...)</span> -&gt;</span>
			<span class="hljs-keyword">return</span> <span class="hljs-literal">undefined</span> <span class="hljs-keyword">unless</span> obj[name]
			<span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> obj[name] == <span class="hljs-string">'function'</span>
				Object.method(name,[args1...,args2...]...) obj
			<span class="hljs-keyword">else</span>
				Object.property(name,[args1...,args2...]...) obj
			
	Object.<span class="hljs-function"><span class="hljs-title">path</span> = <span class="hljs-params">(path=[],separator=<span class="hljs-string">'.'</span>)</span> -&gt;</span>
		<span class="hljs-keyword">return</span> Object.path path.split(separator) <span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> path == <span class="hljs-string">'string'</span>
		[first,rest...] = path
		<span class="hljs-keyword">switch</span> path.length
			<span class="hljs-keyword">when</span> <span class="hljs-number">0</span> <span class="hljs-keyword">then</span> Function.constant <span class="hljs-literal">undefined</span>
			<span class="hljs-keyword">when</span> <span class="hljs-number">1</span> <span class="hljs-keyword">then</span> Object.resolve first
			<span class="hljs-keyword">else</span> Object.resolve(first).<span class="hljs-keyword">then</span> Object.path rest
			
	Object.<span class="hljs-function"><span class="hljs-title">execute</span> = <span class="hljs-params">(fn)</span> -&gt;</span> <span class="hljs-function"><span class="hljs-params">(obj)</span> -&gt;</span>
		fn.call obj
		<span class="hljs-keyword">return</span> obj</pre></div></div>
            
        </li>
        
        
        <li id="section-3">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-3">&#182;</a>
              </div>
              <h2 id="typed-objects">Typed objects</h2>

            </div>
            
            <div class="content"><div class='highlight'><pre>	
	Object.Of = Function.From<span class="hljs-function"><span class="hljs-params">(Constructor)</span> <span class="hljs-params">(constructor)</span> -&gt;</span>
		test = Object.isa constructor
		<span class="hljs-function"><span class="hljs-title">fn</span> = -&gt;</span>
		fn.<span class="hljs-function"><span class="hljs-title">valid</span> = <span class="hljs-params">(obj)</span> -&gt;</span>	Array.reduce(Boolean.<span class="hljs-keyword">and</span>) ( test value <span class="hljs-keyword">for</span> own key, value <span class="hljs-keyword">of</span> obj )
		<span class="hljs-keyword">return</span> fn</pre></div></div>
            
        </li>
        
    </ul>
  </div>
</body>
</html>
